package com.dongdongshop.controller;



import com.dk.data.R;
import com.dk.enums.ResultEnum;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.pojo.TbSpecification;
import com.dongdongshop.pojo.TbTypeTemplate;
import com.dongdongshop.service.BrandService;
import com.dongdongshop.service.SpecificationService;
import com.dongdongshop.service.TbtypeService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
//模板管理
@Controller
@RequestMapping("type")
public class TbtypeController {


    @DubboReference
    TbtypeService ts;

    @DubboReference
    BrandService bs;//品牌表

    @DubboReference
    SpecificationService sfs;//规格表



    //跳转页面
    //增加跳转页面,需要回显规格，与品牌
    @RequestMapping("tiao")
    public String tiao(Model mo){
        List<TbBrand> tb = bs.getlist();
        List<TbSpecification> ts = sfs.getlist();
        mo.addAttribute("b",tb);//品牌
        mo.addAttribute("s",ts);//规格
        return "admin/type_template";
    }

    //查询全部
    @RequestMapping("getall")
    @ResponseBody
    public R<List<TbTypeTemplate>> getall(){
        List<TbTypeTemplate> ls = ts.getall();
        return R.ok().setData(ls);
    }


    //增加
    @RequestMapping("addspec")
    @ResponseBody
    public R addspec(TbTypeTemplate tt){
        ts.addspec(tt);
        return R.ok();
    }


    //修改回显
    @RequestMapping("updatespec")
    @ResponseBody
    public R<TbTypeTemplate> updatespec(Long id){
        if(id==null&&id<=0){
            return R.response(ResultEnum.ARGS_ISNULL);
        }
        TbTypeTemplate template = ts.upbyid(id);
        return R.ok().setData(template);
    }

    //修改
    @RequestMapping("uptype")
    @ResponseBody
    public R uptype(TbTypeTemplate tt){

        ts.uptype(tt);
        return R.ok();
    }


    //删除
    @RequestMapping("deleteid")
    @ResponseBody
    public R deleteid(Long id){
        ts.deleteid(id);
        return R.ok();
    }



}
